﻿namespace LinkedTU.Models
{
    using System;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using LinkedTU.Common.Constants;

    public class Certificate : BaseDbEntity
    {
        public int CertificateId { get; set; }

        [Required]
        [MinLength(ValidationConstants.MinCertificateLength)]
        [MaxLength(ValidationConstants.MaxCertificateLength)]
        public string Name { get; set; }

        [Required]
        [MaxLength(ValidationConstants.MaxUrlLength)]
        [DataType(DataType.Url)]
        public string Url { get; set; }

        public DateTime StartDate { get; set; }

        public DateTime? EndDate { get; set; }

        public int Order { get; set; }

        [Required]
        [MinLength(ValidationConstants.MinCompanyNameLength)]
        [MaxLength(ValidationConstants.MaxCompanyNameLength)]
        public string AuthorityName { get; set; }

        public virtual ProfileInfo Owner { get; set; }

        [NotMapped]
        public bool DoesExpire
        {
            get
            {
                return this.EndDate.HasValue;
            }
        }

        [NotMapped]
        public bool HasExpired
        {
            get
            {
                return this.EndDate.HasValue && this.EndDate <= DateTime.Now;
            }
        }
    }
}
